import {
 queryApplyApiByIdReq, queryGetApiGroupReq, queryGetApiTestInfoReq, queryLogReq, queryTestApiReq,
} from './api'

export default {
  namespace: 'apiMarket',
  state: {
    dictionaryList: [],
  },
  effects: {
    // 左侧目录
    * queryGetApiGroup({ params, cb }, { call, put }) {
      const res = yield call(queryGetApiGroupReq, params)
      if (res && cb) {
        cb(res)
      }
      yield put({
        type: 'save',
        payload: {
          dictionaryList: res || [],
        },
      })
    },

    * queryApplyApiById({ params, cb }, { call, put }) {
      const res = yield call(queryApplyApiByIdReq, params)
      if (cb) {
        cb(res)
      }
    },

    * queryTestApi({ params, cb }, { call, put }) {
      const res = yield call(queryTestApiReq, params)
      if (cb) {
        cb(res)
      }
    },

    * queryGetApiTestInfo({ params, cb }, { call, put }) {
      const res = yield call(queryGetApiTestInfoReq, params)
      if (cb) {
        cb(res)
      }
    },

    * queryLog({ params, cb }, { call, put }) {
      const res = yield call(queryLogReq, params)
      if (cb) {
        cb(res)
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      }
    },
  },
}
